#!/usr/bin/env python3
#-*- coding:utf-8 -*-
# Power by 2020-05-19 23:57:00

"""
File: load_data.py
Author: "caotian6666"
Email: "caotiandyx@163.com"
Github: "https://gitee.caotian6666.com"
Description: 加载房价数据，有13个维度和一个房价维度
"""
import os
import numpy as np
def load_data():
    """load data from csv .format (矩阵+归一化)
    :returns: TODO

    """
    cur_path=os.path.abspath(os.curdir)
    file_path=os.path.join(cur_path,"housing.data")
    data=np.fromfile(file_path,sep=' ')
    feature_names=[ 'CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD', 'TAX', 'PTRATIO', 'B', 'LSTAT', 'MEDV' ]
    data=data.reshape([data.shape[0]//len(feature_names),len(feature_names)])
    #归一化
    offset=int(data.shape[0] * 0.8)
    traing_data=data[:offset]
    maxval=traing_data.max(axis=0)
    minval=traing_data.min(axis=0)
    avgval=traing_data.sum(axis=0)/traing_data.shape[0]
    for index in range(len(feature_names)):
        data[:,index]=(data[:,index]-avgval[index])/(maxval[index]-minval[index])
    training_data=data[:offset]
    test_data=data[offset:]
    return training_data,test_data
training_data,test_data=load_data()
x = training_data[:, :-1]
y = training_data[:, -1:]
w = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, -0.1, -0.2, -0.3, -0.4, 0.0]
w = np.array(w).reshape([13, 1])
t=np.dot(x[0],w)
#print(x[0])
#print(y[0])
#print(t) 
b=-0.2
z=t+b
#print(z)

